<template>
	<view>
		<uni-nav-bar :title="title" :statusBar="true" :border="false" left-icon="back" :fixed="true"
			@clickLeft="$tab.back()" @clickRight="deleUser">
			<block slot="right">
				<view class="bg-theme px-16 py-12 round-4 text-FFF">
					删除{{delNum}}
				</view>
			</block>
		</uni-nav-bar>

		<view class="px-20 py-24 bg-FFF mt-16">
			<u-search placeholder="手机号/昵称" v-model="keyword" @custom="getDetail"></u-search>
		</view>

		<view class="px-20 py-28 bg-FFF mt-16">
			<view class="" v-for="(item,index) in userList" :key="item.id">
				<view class="flex items-center">
					<u-checkbox-group shape="circle" v-model="item.isSelect" @change="selectChange(index)">
						<u-checkbox name="select">
						</u-checkbox>
					</u-checkbox-group>
					<image :src="item.userInfo.avatar" class="image-80 round" mode=""></image>
					<view class="mt-12 text-32 font-500 u-line-1 ml-24">
						{{item.userInfo.nickName}}
					</view>
				</view>
				<u-divider></u-divider>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userList: null,
				id: null,
				title: "",
				keyword: "",
				delNum: "",
				delIdArr: [],
				userInfo: this.$store.getters.userInfo,
			};
		},
		onLoad(e) {
			this.id = e.id
			this.title = e.title
			this.getDetail()
		},
		methods: {
			async deleUser() {
				const res = await this.$Api.chat.deleteGroupUser({
					groupId: this.id,
					deleteUserIds: this.delIdArr.join(',')
				})
				console.log('删人', res)
				this.$tab.back(1000)
			},
			async hendClick(item) {
				const res = await this.$Api.chat.usersIsFriend({
					userId1: item.userInfo.userId
				})
				if (res.data) {
					this.$tab.nav(`/pages/chat2/userDetail?userId=${item.userInfo.userId}`)
				} else {
					this.$tab.nav(`/pages/chat2/addFriend?userName=${item.userInfo.userId}`)
				}
			},
			async getDetail() {
				const res = await this.$Api.chat.groupUserList({
					groupId: this.id,
					keyword: this.keyword,
					pageNum: 1,
					pageSize: 100
				})
				this.userList = res.rows
				this.userList = this.userList.filter(item => {
					return item.userId != this.userInfo.userId
				})
				this.userList.forEach(item => {
					item.isSelect = []
				})
			},
			selectChange() {
				let tem = 0
				this.delIdArr = []
				setTimeout(() => {
					this.userList.forEach(item => {
						if (item.isSelect.length > 0) {
							tem++
							this.delIdArr.push(item.userId)
							if (tem > 0) {
								this.delNum = `(${tem})`
							}
						}
					})
				}, 300)
			}
		}
	}
</script>

<style lang="scss">
	/deep/ .u-radio-group {
		flex: 0;
	}
</style>